package com.yanqu.road.dao.impl.activity.fellingtrees;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.fellingtrees.config.FellingTreesWeaponsConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class FellingTreesWeaponsConfigDaoImpl extends TempDao {

    private static String getFellingTreesWeaponsConfigSql = "select * from `t_s_activity_ftrees_weapons` where `activityId`=?";

    public Map<Integer, FellingTreesWeaponsConfig> getFellingTreesWeaponsConfigMap(int activityId) {
        Map<Integer, FellingTreesWeaponsConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFellingTreesWeaponsConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FellingTreesWeaponsConfig fellingTreesWeaponsConfig = new FellingTreesWeaponsConfig();
                fellingTreesWeaponsConfig.setActivityId(rs.getInt("activityId"));
                fellingTreesWeaponsConfig.setId(rs.getInt("id"));
                fellingTreesWeaponsConfig.setType(rs.getInt("type"));
                fellingTreesWeaponsConfig.setIcon(rs.getInt("icon"));
                fellingTreesWeaponsConfig.setQuality(rs.getInt("quality"));
                fellingTreesWeaponsConfig.setBaseAttack(rs.getInt("baseAttack"));
                fellingTreesWeaponsConfig.setEffectMode(rs.getString("effectMode"));
                fellingTreesWeaponsConfig.setEffectAttack(rs.getInt("effectAttack"));
                fellingTreesWeaponsConfig.setDropLevel(rs.getString("dropLevel"));
                fellingTreesWeaponsConfig.setWeight(rs.getInt("weight"));
                fellingTreesWeaponsConfig.setParam(rs.getString("param"));
                map.put(fellingTreesWeaponsConfig.getId(), fellingTreesWeaponsConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
